<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PageRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            //
            'name' => 'required|max:20',
            'entry' => 'required|max:20',
            'tag' => 'required|json',
            'file' => 'mimes:zip',
        ];

        if($this->method()==='PUT'){

        }else{
            $rules['file']= 'required|mimes:zip';
        }
        return $rules;
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '名称必填',
            'name.max' => '名称必须小于20个字符',
            'entry.required' => '入口必填',
            'entry.max' => '入口必须小于20个字符',
            'tag.required' => '标签必填',
            'tag.json' => '标签必须填写为JSON字符串',
            'file.required' => '请选择要上传的zip文件',
            'file.mimes' => '文件类型必须为zip'
        ];
    }
}
